package com.yuanqi.repository;

import com.yuanqi.domain.Receipt;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public interface ReceiptRepository extends JpaRepository<Receipt, Long> {
    
    List<Receipt> findByCustomerId(Long customerId);
    
    List<Receipt> findByReceiptDateBetween(LocalDate startDate, LocalDate endDate);
    
    @Query("SELECT SUM(r.amount) FROM Receipt r WHERE r.receiptDate BETWEEN ?1 AND ?2")
    Double getTotalReceiptAmount(LocalDate startDate, LocalDate endDate);
    
    boolean existsByReceiptCode(String receiptCode);
}


